package visualcbir.visualstructures.spiral;

import visualcbir.*;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.MultipleGradientPaint.CycleMethod;
import java.awt.Point;
import java.awt.RadialGradientPaint;
import java.awt.geom.GeneralPath;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import visualcbir.exception.NullBackStructureException;
import visualcbir.util.VSUtils;

/**
 *
 * @author sheila
 */
public class VSSpiralBackStructureView implements IBackStructureView{
    private ArrayList <Point> aoPoints;

    @Override
    public void drawBackStructure(Graphics g) throws NullBackStructureException{
        if( aoPoints == null ){
            throw new NullBackStructureException();
        }
        GeneralPath oGeneralPath=new GeneralPath();
        oGeneralPath.moveTo(aoPoints.get(0).getX(),aoPoints.get(0).getY());
        for (int i = 1; i < this.aoPoints.size(); i++)
            oGeneralPath.lineTo(aoPoints.get(i).x,aoPoints.get(i).y);
        
        Graphics2D g2d=((Graphics2D)g);
        //***** Background color rendering **************
        Point2D center = new Point2D.Float(aoPoints.get(0).x, aoPoints.get(0).y);
        int r = Math.abs( aoPoints.get(0).x - aoPoints.get(aoPoints.size()-1).x );
        int difx  = aoPoints.get(0).x - aoPoints.get(aoPoints.size()-1).x;
        int dify = aoPoints.get(0).y - aoPoints.get(aoPoints.size()-1).y;
        double rad = Math.sqrt(Math.pow(difx, 2) + Math.pow(dify, 2));
        float radius = (float) Math.abs( rad );
        float[] dist = {0.0f, 0.35f, 0.9f, 1.0f};
        Color[] colors = {Color.WHITE, Color.LIGHT_GRAY, Color.DARK_GRAY, Color.BLACK};
        RadialGradientPaint p = new RadialGradientPaint(center, radius, dist, colors,CycleMethod.NO_CYCLE);
        g2d.setPaint(p);
        g2d.fill(oGeneralPath);        
        //***********************************************
        g2d.setStroke(new BasicStroke(2.0f, BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND, 10.0f, null, 0.0f));
        g.setColor(Color.red);
        g2d.draw(oGeneralPath);
        
        VSUtils.resetGraphics(g);
    }

    @Override
    public void setObject(Object oObject) {
        this.aoPoints=(ArrayList <Point>)oObject;
    }
}
